home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1996 February / EnigmA AMIGA RUN 04 (1996)(G.R. Edizioni)(IT)[!][issue 1996-02][Skylink CD III].iso / earcd / util1 / slwbts18.lha / SlowBootSrc / SlowBoot.c < prev    next >
C/C++ Source or Header  |  1995-10-23  |  4KB  |  189 lines

  1. /*************************************************************************
  2.  *
  3.  * SlowBoot
  4.  *
  5.  * Copyright ©1995 Lee Kindness cs2lk@scms.rgu.ac.uk
  6.  *
  7.  * Read SlowBoot.guide (from the main archive) for distribution details.
  8.  *
  9.  * SlowBoot.c
  10.  */
  11.  
  12. #include "gst.c"
  13. #include "SlowBoot_rev.h"
  14.  
  15. const STRPTR vtag = VERSTAG;
  16. STRPTR defcmd = "Execute <>CON:///-1/AmigaDOS/AUTO/NOCLOSE/SMART s:startup-sequence";
  17.  
  18. void NewAssign(STRPTR name, STRPTR to, BPTR def);
  19. void NewAssignLate(STRPTR name, STRPTR to, BPTR def);
  20.  
  21.  
  22. /*************************************************************************
  23.  * NewAssign() -- Reassign an assign
  24.  */
  25.  
  26. void NewAssign(STRPTR name, STRPTR to, BPTR def)
  27. {
  28.     /* Remove old assign */
  29.     if( AssignLock(name, NULL) )
  30.     {
  31.         BPTR lock;
  32.         
  33.         /* Lock new destination */
  34.         if( lock = Lock(to, ACCESS_READ) )
  35.         {
  36.             /* Add Assign */
  37.             if( !AssignLock(name, lock) )
  38.                 UnLock(lock);
  39.         } else
  40.         {
  41.             /* Assign to default location */
  42.             lock = DupLock(def);
  43.             if( !AssignLock(name, lock) )
  44.                 UnLock(lock);
  45.         }
  46.     }
  47. }
  48.  
  49.  
  50. /*************************************************************************
  51.  * NewAssignLate() -- Reassign a late (defered) assign
  52.  */
  53.  
  54. void NewAssignLate(STRPTR name, STRPTR to, BPTR def)
  55. {
  56.     /* Remove old assign */
  57.     if( AssignLock(name, NULL) )
  58.     {
  59.         /* Add Assign */
  60.         if( !AssignLate(name, to) )
  61.         {
  62.             BPTR lock;
  63.             /* Assign to default location */
  64.             lock = DupLock(def);
  65.             if( !AssignLock(name, lock) )
  66.                 UnLock(lock);
  67.         }
  68.     }
  69. }
  70.  
  71.  
  72. /*************************************************************************
  73.  * main()
  74.  */
  75.  
  76. #define OPT_DEVICE 0
  77. #define OPT_WAIT 1
  78. #define OPT_CMD 2
  79. #define OPT_MAX 3
  80. #define TEMPLATE "DEVICE/A,WAIT/N/K,CMD=COMMAND/K"
  81.  
  82. void main( void )
  83. {
  84.     struct Process *myproc;
  85.     
  86.     /* Check Library versions */
  87.     if( (((struct Library *)SysBase)->lib_Version < 36) ||
  88.         (((struct Library *)DOSBase)->lib_Version < 36) )
  89.         return;
  90.     
  91.     /* Find our process */
  92.     if( myproc = (struct Process *)FindTask(NULL) )
  93.     {
  94.         APTR oldwinp;
  95.         struct RDArgs *rdargs;
  96.         LONG args[OPT_MAX] = {0, 0, 0};
  97.         LONG delay;
  98.         #define dev (STRPTR)args[OPT_DEVICE]
  99.         #define cmd (STRPTR)args[OPT_CMD]
  100.         args[OPT_CMD] = (LONG)defcmd;
  101.         
  102.         /* Store away original contents */
  103.         oldwinp = myproc->pr_WindowPtr;
  104.         
  105.         /* We don't want any requesters */
  106.         myproc->pr_WindowPtr = (APTR)-1L;
  107.         
  108.         /* Get options */
  109.         if (rdargs = ReadArgs(TEMPLATE, (LONG *)&args, NULL))
  110.         {
  111.             BPTR lock;
  112.             
  113.             if( args[OPT_WAIT] )
  114.                 delay = (*((LONG *)args[OPT_WAIT])) * 50;
  115.             else
  116.                 delay = 50;
  117.             
  118.             /* Test for dev... Has it spun up? */
  119.             if( lock = Lock(dev, ACCESS_READ) )
  120.             {
  121.                 BPTR dupsys;
  122.                 BOOL ok;
  123.                 
  124.                 /* The device has spun up correctly, reassign assigns */
  125.                 Forbid();
  126.                 ok = FALSE;
  127.                 if( AssignLock("SYS", NULL) )
  128.                 {
  129.                     dupsys = DupLock(lock);
  130.                     if( AssignLock("SYS", dupsys) )
  131.                         ok = TRUE;
  132.                 }
  133.                 Permit();
  134.                 
  135.                 if( ok )
  136.                 {
  137.                     BPTR olddir;
  138.                     BPTR con;
  139.                     
  140.                     NewAssign("C", "SYS:C", lock);
  141.                     NewAssign("S", "SYS:S", lock);
  142.                     NewAssign("LIBS", "SYS:LIBS", lock);
  143.                     NewAssign("DEVS", "SYS:DEVS", lock);
  144.                     NewAssign("FONTS", "SYS:FONTS", lock);
  145.                     NewAssign("L", "SYS:L", lock);
  146.                     NewAssignLate("ENVARC", "SYS:Prefs/Env-Archive", lock);
  147.                     
  148.                     /* Change cd to SYS: */
  149.                     olddir = CurrentDir(lock);
  150.                     
  151.                     /* Open NIL: */
  152.                     if( con = Open("NIL:", MODE_OLDFILE) )
  153.                     {
  154.                         /* Execute startup-sequence */
  155.                         if( SystemTags(cmd, SYS_Input,  con,
  156.                                     SYS_Output, 0,
  157.                                     SYS_Asynch, TRUE,
  158.                                     TAG_END ) == -1 )
  159.                             Close(con);
  160.                     }
  161.                     
  162.                     /* Change back to old dir */
  163.                     CurrentDir(olddir);
  164.                 }
  165.                 UnLock(lock);
  166.             } else
  167.             {
  168.                 /* Drive has not spun-up, lets wait a while */
  169.                 if( delay > 0 )
  170.                     Delay(delay);
  171.                 
  172.                 /* And then reboot */
  173.                 Disable();
  174.                 ColdReboot();
  175.                 Enable();
  176.                 /* .
  177.                  * .
  178.                  * .
  179.                  * This NEVER returns...
  180.                  *
  181.                  */
  182.             }
  183.             FreeArgs(rdargs);    
  184.         }
  185.         /* Restore old pointer */
  186.         myproc->pr_WindowPtr = oldwinp;
  187.     }
  188. }
  189.